import {App} from "vue";
import "./layout/styles/main.css";


function getComponentName(key: string){
    if(!key){
        return "";
    }
    const paths = key.split("/");
    const name = paths
        .filter(it => !!it && it !== ".")
        .reverse()
        .find(it => it !== "index.vue" && it !== "index.ts" && it !== "index.js")
        ?.replace(".vue", "")
    return name || "";
}

// 注册当前目录下的所有组件
const components = import.meta.glob("./common/**/*.vue");
export function registerComponents(app: App): void{
    Object.entries(components).forEach(([ele, module]) => {
      app.component(getComponentName(ele), defineAsyncComponent(module));
    });
    
}